from MsgProcess import MsgProcess, MsgType


class Lamp_wifi(MsgProcess):
    '''万能开关插件'''
    def Text(self, message):

        Data = message['Data']

        #判读是否是8266发过来的消息类型
        if isinstance(Data, dict) and 'type' in dict(Data).keys() and  Data['type'] == 'lamp' :
            if Data["message"]=="1":
                self.say("灯已经打开")
            if Data["message"]=="0":
                self.say("灯已经关闭")
        else:
           
            #定义消息类型，发送消息到8266
            if "打开" in Data  or "启动" in Data : 
                self.send(MsgType=MsgType.Text, Receiver="MqttProxy", Data={"type":"lamp","message":"1"} )
            if "关闭" in Data  or "停止" in Data:
                self.send(MsgType=MsgType.Text, Receiver="MqttProxy", Data={"type":"lamp","message":"0"} )